package com.ticket.websocket;


import com.ticket.common.string.StringUtil;
import com.ticket.common.time.CommonFunction;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

import java.util.Date;
public class main {
    public  String currentTime= CommonFunction.format(new Date(), "yyyyMMddHH")+"";
    public static void read(String filename) {

       read(filename, "utf-8",15);
    }

    public static void read(String filename, String charset,int end) {

        RandomAccessFile rf = null;
        try {
            rf = new RandomAccessFile(filename, "r");
            long len = rf.length();
            long start = rf.getFilePointer();
            long nextend = start + len - 1;
            String line;
            rf.seek(nextend);
            int c = -1;
            int i=0;
            while (nextend > start) {
                c = rf.read();
                if (c == '\n' || c == '\r') {
                    line = rf.readLine();
                    if (line != null && line.trim().length()!=0 && i< end) {
                        System.out.println(new String(line.getBytes("ISO-8859-1"), charset));
                    }
                    nextend--;
                }
                nextend--;
                rf.seek(nextend);
                if (nextend == 0) {// 当文件指针退至文件开始处，输出第一行
                    System.out.println(rf.readLine());
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (rf != null)
                    rf.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String args[]) {
        //read("/upload/afc1fc978dfb486c8cd3eb94ec87cc2cd-afc1fc978dfb486c8cd3eb94ec87cc2cd11111.txt", "utf-8",15);
        main  main=  new main();
        for (int i=1; ;i++)
        System.out.println(main.currentTime);
    }
}
